<?php
declare (strict_types = 1);

namespace app\middleware;

use app\BaseController;
use think\facade\Cache;

class Check extends BaseController
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $token = $request->header('Authorization', '');
        $request->cacheInfo =Cache::store('redis')->get($token);

        //判断是否登录
        if (empty($request->cacheInfo)){
            return $this->returnJson(self::NOT_LOGGED,'未登入，跳转登入页');
        }
        $request->user_id = $request->cacheInfo['id'];
        return $next($request);
    }
}
